//+------------------------------------------------------------------+
//|                                      Easy iCustom and Alerts.mq4 |
//|                                                       Codersguru |
//|                                         http://www.forex-tsd.com |
//+------------------------------------------------------------------+


#property copyright "Codersguru"
#property link      "http://www.forex-tsd.com"

#property indicator_chart_window

#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Yellow

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

extern bool Alert_On_Crossing = true;

extern string Pair_1="EURUSD";
extern string Indicator_Name_1="Moving Averages";
extern int TimeFrame_1=0;
extern int Line_1=0;
extern double Parameter1_1 = 12;
extern double Parameter2_1 = 0;
extern double Parameter3_1 = 1;
extern double Parameter4_1 = -100;
extern double Parameter5_1 = -100;

extern string Pair_2="EURUSD";
extern string Indicator_Name_2="Moving Averages";
extern int TimeFrame_2=0;
extern int Line_2=0;
extern double Parameter1_2 = 144;
extern double Parameter2_2 = 0;
extern double Parameter3_2 = 1;
extern double Parameter4_2 = -100;
extern double Parameter5_2 = -100;

extern string Pair_3="EURUSD";
extern string Indicator_Name_3="Moving Averages";
extern int TimeFrame_3=0;
extern int Line_3=0;
extern double Parameter1_3 = 169;
extern double Parameter2_3 = 0;
extern double Parameter3_3 = 1;
extern double Parameter4_3 = -100;
extern double Parameter5_3 = -100;


int Crossed_1 (double line1 , double line2)
   {
      static int last_direction = 0;
      static int current_direction = 0;
      
      static bool first_time = true;
      if(first_time == true)
      {
         first_time = false;
         return (0);
      }
      
      if(line1>line2)current_direction = 1; //up
      if(line1<line2)current_direction = 2; //down

      if(current_direction != last_direction) //changed 
      {
            last_direction = current_direction;
            return (last_direction);
      }
      else
      {
            return (0); //not changed
      }
   }
int Crossed_2 (double line1 , double line2)
   {
      static int last_direction = 0;
      static int current_direction = 0;
      
      static bool first_time = true;
      if(first_time == true)
      {
         first_time = false;
         return (0);
      }
      
      if(line1>line2)current_direction = 1; //up
      if(line1<line2)current_direction = 2; //down

      if(current_direction != last_direction) //changed 
      {
            last_direction = current_direction;
            return (last_direction);
      }
      else
      {
            return (0); //not changed
      }
   }
int Crossed_3 (double line1 , double line2)
   {
      static int last_direction = 0;
      static int current_direction = 0;
      
      static bool first_time = true;
      if(first_time == true)
      {
         first_time = false;
         return (0);
      }
      
      if(line1>line2)current_direction = 1; //up
      if(line1<line2)current_direction = 2; //down

      if(current_direction != last_direction) //changed 
      {
            last_direction = current_direction;
            return (last_direction);
      }
      else
      {
            return (0); //not changed
      }
   }
int init()
  {
  
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);

   return(0);
  }

int deinit()
  {
   return(0);
  }
int start()
  {
      
     int    counted_bars=IndicatorCounted();
     if (counted_bars>0) counted_bars--;
     int    pos=Bars-counted_bars; 
      
     while(pos>=0)
     {        
         ExtMapBuffer1[pos]= GetIcustomValue(1,pos);
         ExtMapBuffer2[pos]= GetIcustomValue(2,pos);
         ExtMapBuffer3[pos]= GetIcustomValue(3,pos);
         pos--;
     } 
     
     static int isCrossed_1  = 0;
     static int isCrossed_2  = 0;
     static int isCrossed_3  = 0;
     
     if (Alert_On_Crossing)
     {
      if(Parameter1_1!=-100 && Parameter2_1!=-100 && Parameter3_1!=-100) //1 - 2 - 3
      { 
         isCrossed_1 = Crossed_1(GetIcustomValue(1,0),GetIcustomValue(2,0));
         if (isCrossed_1 == 1) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_2 + " (" + Parameter1_2 + ") Upward!" );
         if (isCrossed_1 == 2) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_2 + " (" + Parameter1_2 + ") Downward!" );
         isCrossed_2 = Crossed_2(GetIcustomValue(2,0),GetIcustomValue(3,0));
         if (isCrossed_2 == 1) Alert (Pair_1 + ": " + Indicator_Name_2 + " (" + Parameter1_2 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
         if (isCrossed_2 == 2) Alert (Pair_1 + ": " + Indicator_Name_2 + " (" + Parameter1_2 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
         isCrossed_3 = Crossed_3(GetIcustomValue(1,0),GetIcustomValue(3,0));
         if (isCrossed_3 == 1) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
         if (isCrossed_3 == 2) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
       }
      
      if(Parameter1_1!=-100 && Parameter2_1!=-100 && Parameter3_1==-100) // 1 - 2
      {
         isCrossed_1 = Crossed_1(GetIcustomValue(1,0),GetIcustomValue(2,0));
         if (isCrossed_1 == 1) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_2 + " (" + Parameter1_2 + ") Upward!" );
         if (isCrossed_1 == 2) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_2 + " (" + Parameter1_2 + ") Upward!" );
      }
      
      if(Parameter1_1!=-100 && Parameter2_1==-100 && Parameter3_1!=-100) // 1 - 3
      {
         isCrossed_1 = Crossed_1(GetIcustomValue(1,0),GetIcustomValue(3,0));
         if (isCrossed_1 == 1) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
         if (isCrossed_1 == 2) Alert (Pair_1 + ": " + Indicator_Name_1 + " (" + Parameter1_1 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
      } 
      
      if(Parameter1_1==-100 && Parameter2_1!=-100 && Parameter3_1!=-100) // 2 - 3
      {
         isCrossed_1 = Crossed_1(GetIcustomValue(2,0),GetIcustomValue(3,0));
         if (isCrossed_1 == 1) Alert (Pair_2 + ": " + Indicator_Name_2 + " (" + Parameter1_2 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
         if (isCrossed_1 == 2) Alert (Pair_2 + ": " + Indicator_Name_2 + " (" + Parameter1_2 + ") has been crossed " + Indicator_Name_3 + " (" + Parameter1_3 + ") Upward!" );
      } 
     }
     

   return(0);
  }
  
  double GetIcustomValue(int level ,int shift)
  {
      double value =0;
      
      switch(level)
      {
         case 1 :
         {  
            if(Parameter1_1!=-100 && Parameter2_1==-100 && Parameter3_1==-100 && Parameter4_1==-100 && Parameter5_1==-100)
               value = iCustom(Pair_1,TimeFrame_1,Indicator_Name_1,Parameter1_1,Line_1,shift);
            if(Parameter1_1!=-100 && Parameter2_1!=-100 && Parameter3_1==-100 && Parameter4_1==-100 && Parameter5_1==-100)
               value = iCustom(Pair_1,TimeFrame_1,Indicator_Name_1,Parameter1_1,Parameter2_1,Line_1,shift);
            if(Parameter1_1!=-100 && Parameter2_1!=-100 && Parameter3_1!=-100 && Parameter4_1==-100 && Parameter5_1==-100)
               value = iCustom(Pair_1,TimeFrame_1,Indicator_Name_1,Parameter1_1,Parameter2_1,Parameter3_1,Line_1,shift);
            if(Parameter1_1!=-100 && Parameter2_1!=-100 && Parameter3_1!=-100 && Parameter4_1!=-100 && Parameter5_1==-100)
               value = iCustom(Pair_1,TimeFrame_1,Indicator_Name_1,Parameter1_1,Parameter2_1,Parameter3_1,Parameter4_1,Line_1,shift);
            if(Parameter1_1!=-100 && Parameter2_1!=-100 && Parameter3_1!=-100 && Parameter4_1!=-100 && Parameter5_1!=-100)
               value = iCustom(Pair_1,TimeFrame_1,Indicator_Name_1,Parameter1_1,Parameter2_1,Parameter3_1,Parameter4_1,Parameter5_1,Line_1,shift);
            break;
         }
      
         case 2 :
         {  
            if(Parameter1_2!=-100 && Parameter2_2==-100 && Parameter3_2==-100 && Parameter4_2==-100 && Parameter5_2==-100)
               value = iCustom(Pair_2,TimeFrame_2,Indicator_Name_2,Parameter1_2,Line_2,shift);
            if(Parameter1_2!=-100 && Parameter2_2!=-100 && Parameter3_2==-100 && Parameter4_2==-100 && Parameter5_2==-100)
               value = iCustom(Pair_2,TimeFrame_2,Indicator_Name_2,Parameter1_2,Parameter2_2,Line_2,shift);
            if(Parameter1_2!=-100 && Parameter2_2!=-100 && Parameter3_2!=-100 && Parameter4_2==-100 && Parameter5_2==-100)
               value = iCustom(Pair_2,TimeFrame_2,Indicator_Name_2,Parameter1_2,Parameter2_2,Parameter3_2,Line_2,shift);
            if(Parameter1_2!=-100 && Parameter2_2!=-100 && Parameter3_2!=-100 && Parameter4_2!=-100 && Parameter5_2==-100)
               value = iCustom(Pair_2,TimeFrame_2,Indicator_Name_2,Parameter1_2,Parameter2_2,Parameter3_2,Parameter4_2,Line_2,shift);
            if(Parameter1_2!=-100 && Parameter2_2!=-100 && Parameter3_2!=-100 && Parameter4_2!=-100 && Parameter5_2!=-100)
               value = iCustom(Pair_2,TimeFrame_2,Indicator_Name_2,Parameter1_2,Parameter2_2,Parameter3_2,Parameter4_2,Parameter5_2,Line_2,shift);
            break;
         }
      
         case 3 :
         {  
            if(Parameter1_3!=-100 && Parameter2_3==-100 && Parameter3_3==-100 && Parameter4_3==-100 && Parameter5_3==-100)
               value = iCustom(Pair_3,TimeFrame_3,Indicator_Name_3,Parameter1_3,Line_3,shift);
            if(Parameter1_3!=-100 && Parameter2_3!=-100 && Parameter3_3==-100 && Parameter4_3==-100 && Parameter5_3==-100)
               value = iCustom(Pair_3,TimeFrame_3,Indicator_Name_3,Parameter1_3,Parameter2_3,Line_3,shift);
            if(Parameter1_3!=-100 && Parameter2_3!=-100 && Parameter3_3!=-100 && Parameter4_3==-100 && Parameter5_3==-100)
               value = iCustom(Pair_3,TimeFrame_3,Indicator_Name_3,Parameter1_3,Parameter2_3,Parameter3_3,Line_3,shift);
            if(Parameter1_3!=-100 && Parameter2_3!=-100 && Parameter3_3!=-100 && Parameter4_3!=-100 && Parameter5_3==-100)
               value = iCustom(Pair_3,TimeFrame_3,Indicator_Name_3,Parameter1_3,Parameter2_3,Parameter3_3,Parameter4_3,Line_3,shift);
            if(Parameter1_3!=-100 && Parameter2_3!=-100 && Parameter3_3!=-100 && Parameter4_3!=-100 && Parameter5_3!=-100)
               value = iCustom(Pair_3,TimeFrame_3,Indicator_Name_3,Parameter1_3,Parameter2_3,Parameter3_3,Parameter4_3,Parameter5_3,Line_3,shift);
            break;
         }
      }
       
      return (value);

  }